<template>
  <div style="display: flex">
    <!--左侧区域-->
    <div :style="{width:(isCollapse? '64px' : '208px')}">
      <!--   左侧菜单栏   -->
      <el-menu
          background-color="#304156"
          style="width: 100%;height: 100%;min-height: 100vh;"
          text-color="#fff"
          active-text-color="#ff0"
          :collapse-transition="false"
          :collapse="isCollapse"
          unique-opened router
          @select="selectMeny"
      >
        <!--    菜单栏中顶部条    -->
        <el-row :gutter="10" style="padding-top: 10px">
          <el-col :span="2"></el-col>
          <el-col :span="7" style="padding-left: 7px">
            <el-avatar style="width: 35px;height: 35px" src="/imgs/admin/logo.png"></el-avatar>
          </el-col>
          <el-col :span="isCollapse ? 0 : 13" style="">
            <router-link to="/"
                         style="position: relative; top: 6px;left: 2px; color: #fff;text-decoration: none;font-weight: 700;">
              后台管理系统
            </router-link>
          </el-col>
        </el-row>
        <el-menu-item index="statistics">
          <template #title>
            <el-icon style="font-size: 21px;">
              <User/>
            </el-icon>
            <span >首页</span>
          </template>
        </el-menu-item>
        <el-sub-menu index="2">
          <template #title>
            <el-icon style="font-size: 21px;">
              <User/>
            </el-icon>
            <span>用户管理</span>
          </template>
          <el-menu-item index="/user">用户列表</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon style="font-size: 21px;">
              <Van/>
            </el-icon>
            <span>房间管理</span>
          </template>
          <el-menu-item index="/room">房间信息</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
          <template #title>
            <el-icon style="font-size:21px;">
              <Place/>
            </el-icon>
            <span>订单管理</span>
          </template>
          <el-menu-item index="/order">订单列表</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="5">
          <template #title>
            <el-icon style="font-size:21px;">
              <Location/>
            </el-icon>
            <span>评价列表</span>
          </template>
          <el-menu-item index="/evaluate">评价管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="6">
          <template #title>
            <el-icon style="font-size:21px;">
              <MessageBox/>
            </el-icon>
            <span>数字字典</span>
          </template>
          <el-menu-item index="/dict">字典管理</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </div>
    <!-- 右侧区域-->
    <!--    calc使用是要在运算符前后加空格-->
    <div :style="{width:(isCollapse? 'calc(100% - 64px)': 'calc(100% - 208px)')}">
      <!--      右侧顶部条菜单栏-->
      <el-header style="background-color:#fff;padding-top: 22px;height: 10vh">
        <!--   右侧顶部按钮 折叠图标+退出登录   -->
        <el-row :gutter="10">
          <el-col :span="18">
            <el-icon @click="changeCollapse()" style="font-size: 20px;position: relative; top: 3px">
              <Expand/>
            </el-icon>
          </el-col>
          <!--   用户名与退出登录     -->
          <el-col :span="6" style="position: relative">
            <el-dropdown trigger="click" style="position: absolute;right: 20px">
            <span style="font-size: 19px;font-weight: 700;">
              {{ user.username }}
            <el-icon><arrow-down/></el-icon>
            </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout()">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row>
        <!--      面包屑导航-->
        <el-breadcrumb separator="/" style="position: relative;top: 20px;">
          <el-breadcrumb-item>首页</el-breadcrumb-item>
          <el-breadcrumb-item v-for="item in breadcrumb">{{item}}</el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>
      <el-main style="padding: 0; min-height: 90vh;overflow-y: auto">
        <router-view />
      </el-main>
    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import router from "@/router";

const isCollapse = ref(false);
const user = ref(getUser())
// const breadcrumb = ref( JSON.parse(localStorage.getItem('breadcrumb'))||['用户管理','用户列表'])
const breadcrumb = ref( ['用户管理','用户列表'])

onMounted(() => {
})
let map = {
  '/statistics':['首页'],
  '/user':['用户管理','用户列表'],
  '/room': ['房间类型','房间信息'],
  '/order': ['订单管理','订单列表'],
  '/evaluate':['评价管理','评价列表'],
  '/dict':['数据字典','字典管理']

}
const selectMeny = (index) => {
  breadcrumb.value = map[index]
  localStorage.setItem('breadcrumb',JSON.stringify(breadcrumb.value))
}
const changeCollapse = () => {
  isCollapse.value = !isCollapse.value
}
const logout = () => {
  if (confirm('确认要退出吗?')){
    localStorage.removeItem('user')
    localStorage.removeItem('breadcrumb')
    router.push('/login')
    user.value = '';
  }
}
</script>
